<?php

//display news

class Controller extends controllerBase {

	public $method = array(0 => 'view');

	public function view($id = 0)
	{
		if($id > 0)
		{

			$query = new Query("SELECT `id` FROM `images` WHERE `id`  = '" . $id ."' ORDER BY `id` LIMIT 0, 1");
		
			#if the item exits, display it, else, error
			if($query->num_rows() > 0)
			{
				echo image_module::displaySingle($id);
			}
			else
			{
				echo display::itemDNE('news entry');
			}
		}
		else
		{
			#display the first X entreis, really, this is the page method
			self::page(1);
		}
	}
	

	public function page($page)
	{
		#displays a page of entries	
		include(MODULE_DIR . 'image/config.php');
		echo image_module::page($page, $config['modules']['images']['items-per-page']);
		
	}
	
	//display all the news entries for a specific month
	public function archive($year = 0)
	{
		include(MODULE_DIR . 'image/config.php');
		
		if($year == 0)	//no year was set, this years archives + previous years
		{
			echo image_module::archiveImages();
			
			//get all years
			echo image_module::archiveYears();
		}
		else
		{		
			echo image_module::archive($year);
		}
	}
	
	
}
?>